﻿namespace Sai.Test.TestDataBuilders
{
	using System.Text;
	using System.Collections.Generic;

	public class SandcastleProjectBuilder : IBuildable
	{
		private List<string> files = new List<string>();
		private List<string> folders = new List<string>();
		private string contentLayout = "project.content";

		public static SandcastleProjectBuilder SandcastleProject()
		{
			return new SandcastleProjectBuilder();
		}

		public SandcastleProjectBuilder WithFile(string fileName)
		{
			this.files.Add(fileName);

			return this;
		}

		public SandcastleProjectBuilder WithFolder(string folderName)
		{
			this.folders.Add(folderName);

			return this;
		}
		
		public SandcastleProjectBuilder WithLayout(string fileName)
		{
			this.contentLayout = fileName;

			return this;
		}

		public string Build()
		{
			var builder = new StringBuilder();

			builder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
			builder.AppendLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" ToolsVersion=\"4.0\">");
			builder.AppendLine("<PropertyGroup>");
			builder.AppendLine("<!-- The configuration and platform will be used to determine which");
			builder.AppendLine("assemblies to include from solution and project documentation");
			builder.AppendLine("sources -->");
			builder.AppendLine("<Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
			builder.AppendLine("<Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>");
			builder.AppendLine("<SchemaVersion>2.0</SchemaVersion>");
			builder.AppendLine("<ProjectGuid>{8a069b82-779e-4f9c-93a8-5cfa2ccc41a3}</ProjectGuid>");
			builder.AppendLine("<SHFBSchemaVersion>1.9.3.0</SHFBSchemaVersion>");
			builder.AppendLine("<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual");
			builder.AppendLine("Studio adds them anyway -->");
			builder.AppendLine("<AssemblyName>Documentation</AssemblyName>");
			builder.AppendLine("<RootNamespace>Documentation</RootNamespace>");
			builder.AppendLine("<Name>Documentation</Name>");
			builder.AppendLine("<!-- SHFB properties -->");
			builder.AppendLine("<OutputPath>\\Help\\</OutputPath>");
			builder.AppendLine("<HtmlHelpName>Sai</HtmlHelpName>");
			builder.AppendLine("<Language>en-US</Language>");
			builder.AppendLine("<HelpTitle>Sai.Net</HelpTitle>");
			builder.AppendLine("<PlugInConfigurations>");
			builder.AppendLine(" <PlugInConfig id=\"Additional Content Only\" enabled=\"False\">");
			builder.AppendLine("<configuration />");
			builder.AppendLine("</PlugInConfig>");
			builder.AppendLine("</PlugInConfigurations>");
			builder.AppendLine("<CleanIntermediates>False</CleanIntermediates>");
			builder.AppendLine("<DocumentationSources>");
			builder.AppendLine("<DocumentationSource sourceFile=\"Sai.Cecil\\bin\\Debug\\Sai.Cecil.dll\" />");
			builder.AppendLine("<DocumentationSource sourceFile=\"Sai.Core\\bin\\Debug\\Sai.Core.dll\" />");
			builder.AppendLine("</DocumentationSources>");
			builder.AppendLine("<FeedbackEMailAddress>help%40gmail.com</FeedbackEMailAddress>");
			builder.AppendLine("<PresentationStyle>vs2005</PresentationStyle>");
			builder.AppendLine("<SyntaxFilters>CSharp, VisualBasic</SyntaxFilters>");
			builder.AppendLine("<HelpFileVersion>0.1.0.0</HelpFileVersion>");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<!-- There are no properties for these groups.  AnyCPU needs to appear in");
			builder.AppendLine("order for Visual Studio to perform the build.  The others are optional");
			builder.AppendLine("common platform types that may appear. -->");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|x86' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|x86' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|x64' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|x64' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|Win32' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|Win32' \">");
			builder.AppendLine("</PropertyGroup>");
			builder.AppendLine("<ItemGroup>");
	
			foreach (var folder in this.folders)
			{
				builder.AppendLine(string.Format("\t<Folder Include=\"{0}\" />", folder));
			}

			builder.AppendLine("</ItemGroup>");

			builder.AppendLine("<ItemGroup>");
			builder.AppendLine(string.Format("\t<ContentLayout Include=\"{0}\" />", this.contentLayout));
			builder.AppendLine("</ItemGroup>");

			builder.AppendLine("<ItemGroup>");

			foreach (var file in this.files)
			{
				builder.AppendLine(string.Format("\t<Content Include=\"{0}\" />", file));
			}
			
			builder.AppendLine("</ItemGroup>");

			builder.AppendLine("<!-- Import the SHFB build targets -->");
			builder.AppendLine("<Import Project=\"$(SHFBROOT)\\SandcastleHelpFileBuilder.targets\" />");
			builder.AppendLine("</Project>");

			return builder.ToString();
		}

	}
}
